package com.example.demo.controller;


import com.example.demo.entity.Result;
import com.example.demo.entity.View;
import com.example.demo.mapper.MenuMapper;
import com.example.demo.service.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cdn
 * @since 2025-04-29
 */
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Slf4j
@RestController
@RequestMapping("/menu")
public class MenuController implements DisposableBean {

    @Resource
    private MenuMapper baseMapper;



    @Autowired
    private  ApplicationEventPublisher eventPublisher;



    @Value("#{menuServiceImpl.aa()=='1'?consoleLogger:fileLogger}")
    private Logger logger;




    /**
     * @author 蔡定努
     */
    @PostMapping("/sendEvent")
    public Result<?> sendEvent(@RequestBody View order) {
        logger.log("发送事件");
        return Result.success("发送事件2222");
    }

    /**
     * a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z
     * @param args
     */

    public static void main(String[] args) throws IOException {

        File file = new File("/Users/caidingnu/Desktop/tt");
        // create(file,0);
        aa(file);
    }
    public static void create(File file,int deep) throws IOException {
        File file1 = new File(file.getAbsolutePath() + "/" + deep);
        file1.mkdir();
        boolean directory = file.isDirectory();
        if (directory  && deep < 10) {
           create(file1,deep+1);
        }
    }

    /**
     * @author 蔡定努
     */
    public static void aa(File file) {
        boolean directory = file.isDirectory();
        if (directory) {
            File[] files = file.listFiles();
            for (File f : files) {
                aa(f);
            }
        }else {
            System.out.println(file.getAbsolutePath());
        }
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("-----------------");
    }
}
